package cn.com.dcsgo.controller;


import cn.com.dcsgo.model.product.AttrGroup;
import cn.com.dcsgo.result.Result;
import cn.com.dcsgo.service.AttrGroupService;
import cn.com.dcsgo.vo.product.AttrGroupQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/*
接口路径及参数参考前端文件：
uu-preferred-front-end/uuyx-admin/src/api/product/attrGroup.js
 */

/**
 * <p>
 * 属性分组 前端控制器
 * </p>
 *
 * @author Dcsgo
 * @since 2025-04-07
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "商品属性分组")
@RequestMapping("/admin/product/attrGroup")
public class AttrGroupController {
    private final AttrGroupService attrGroupService;

    @ApiOperation("分页查询商品属性分组")
    @GetMapping("{page}/{size}")
    public Result<IPage<AttrGroup>> getPageList(@PathVariable Long page,
                                                @PathVariable Integer size,
                                                AttrGroupQueryVo attrGroupQueryVo) {
        Page<AttrGroup> pageParam = new Page<>(page, size);
        IPage<AttrGroup> pageResult = attrGroupService.selectPage(pageParam, attrGroupQueryVo);
        return Result.ok(pageResult);
    }

    @ApiOperation("通过id获取商品属性分组")
    @GetMapping("get/{id}")
    public Result<AttrGroup> getById(@PathVariable Long id) {
        AttrGroup attrGroup = attrGroupService.getById(id);
        return Result.ok(attrGroup);
    }

    @ApiOperation("添加商品属性分组")
    @PostMapping("save")
    public Result<Serializable> save(@RequestBody AttrGroup attrGroup) {
        attrGroupService.save(attrGroup);
        return Result.ok(null);
    }

    @ApiOperation("通过id更新商品属性分组")
    @PutMapping("update")
    public Result<Serializable> updateById(@RequestBody AttrGroup attrGroup) {
        attrGroupService.updateById(attrGroup);
        return Result.ok(null);
    }

    @ApiOperation("通过id删除商品属性分组")
    @DeleteMapping("remove/{id}")
    public Result<Serializable> removeById(@PathVariable Long id) {
        attrGroupService.removeById(id);
        return Result.ok(null);
    }

    @ApiOperation("通过id批量删除商品属性分组")
    @DeleteMapping("batchRemove")
    public Result<Serializable> removeBathByIds(@RequestBody List<Long> idList) {
        attrGroupService.removeByIds(idList);
        return Result.ok(null);
    }

    @ApiOperation("获取所有商品属性分组")
    @GetMapping("findAllList")
    public Result<List<AttrGroup>> findAllList() {
        List<AttrGroup> attrGroupList = attrGroupService.listOrderById();
        return Result.ok(attrGroupList);
    }
}

